package interview.coding.linkedlist;

public class LinkedListManipulation {

	public void interpolateList(SimpleLinkedList sll) {
		Node slowNode = sll.getHead();
		Node fastNode = sll.getHead();
		
		while(fastNode != null) {
			slowNode = slowNode.getNext();
			fastNode = fastNode.getNext().getNext();
		}
		
		Node midNode = slowNode;
		System.out.println("** midNode is " + midNode.getValue());
		Node startNode = sll.getHead();
		
		// FIXME: this logic is not correct!!
		while(midNode != null) {
			if(startNode.getValue() == slowNode.getValue()) {
				startNode.setNext(null);
			}
			Node startNodeNext = startNode.getNext();
			Node midNodeNext = midNode.getNext();
			midNode.setNext(startNode.getNext());
			startNode.setNext(midNode);
			midNode = midNodeNext;
			startNode = startNodeNext;
		}
	}
}
